import Vue from 'vue'
import Vuex from 'vuex'
import todos from './modules/todos'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    count: 1,
    name: 'zhangsan',
    age: 18,
  },
  mutations: {
    updateCount(state, text) {
      console.log('updateCount',text);
      state.count = text;
    },
    updateName(state, text) {
      console.log('updateName',text);
      state.name = text;
    },
    updateAge(state, text) {
      console.log('updateAge',text);
      state.age = text;
    }
  },
  getters: {
    getCount: (state) => state.count,
    getName: (state) => state.name,
    getAge: (state) => state.age,
  },
  actions: {
    aUpdateCount({ commit }, text) {
      console.log('updateCount');
      commit('updateCount', text);
    },
    aUpdateName({ commit }, text) {
      console.log('updateName');
      commit('updateName', text);
    },
    aUpdateAge({ commit }, text){
      commit('updateAge');
      commit('updateAge', text);
    }
  },
  modules: {
    todos
  }
})
